from fastapi import APIRouter

from core.class_core import create_classes_to_core, get_classes_by_id, update_classes_by_id, delete_classes_by_id, \
    count_classes_by_id, add_count_add
from entity.schema.class_schema import ClassesCreate, Class_userCreaate
from utils.base_response import BaseResponse

classes=APIRouter()

@classes.post("/add")
async def create_classes(classes: ClassesCreate):
    """
    创建课程
    """

    classes=await create_classes_to_core(classes.name)
    return BaseResponse(code=200, message="创建成功", data=None)


@classes.get("/get/{classes_id}")
async def get_classes(classes_id: int):
    """
    获取课程
    """
    classes=await get_classes_by_id(classes_id)
    return BaseResponse(code=200, message="获取成功", data=classes)

@classes.put("/update/{classes_id}")
async def update_classes(classes_id: int, classes: ClassesCreate):
    """
    更新角色
    """
    classes=await update_classes_by_id(classes_id,classes)
    return BaseResponse(code=200, message="更新成功", data=None)

@classes.delete("/delete/{classes_id}")
async def delete_classes(classes_id: int):
    """
    删除角色
    """
    classes=await delete_classes_by_id(classes_id=classes_id)
    return BaseResponse(code=200, message="删除成功", data=None)

@classes.get("/count/{classes_id}")
async def count_classes(classes_id: int):
    """
    计算数量
    """
    classes=await count_classes_by_id(classes_id=classes_id)
    return BaseResponse(code=200, message="查询成功", data=classes)

@classes.post("/count/add")
async def add_count(class_user: Class_userCreaate):
    """
    增加数量
    """
    classes=await add_count_add(class_user.class_id,class_user.user_id)
    return BaseResponse(code=200, message="查询成功", data=None)